package smarties.style;

import java.awt.Graphics2D;
import java.awt.Stroke;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import smarties.SmartEdge;
import smarties.SmartNode;

import com.touchgraph.graphlayout.TGPanel;

@XmlRootElement(name = "emptyRingStyle")
public class EmptyRingStyle extends CircleStyle
{
	@XmlTransient
	private int	margin	= 5;

	@XmlElement(name = "margin")
	public int getMargin()
	{
		return this.margin;
	}

	public void setMargin(int margin)
	{
		this.margin = margin;
	}

	@Override
	public void paintNodeBody(SmartNode node, Graphics2D g,
			TGPanel<SmartNode, SmartEdge> tgPanel)
	{
		if (node.isSelected())
		{
			g.setColor(this.getSmartColor().getColor());
		}
		else
		{
			g.setColor(SmartNode.getUnselectedSmartColor().getColor());
		}

		if (this.getRadius() < node.getHeight()
				&& this.getRadius() < node.getWidth())
		{
			this.setRadius(node.getHeight());
		}

		int ix = (int) node.drawx;
		int iy = (int) node.drawy;

		int radius = this.getRadius() - this.getBorder() - this.margin;

		if (radius < 0)
		{
			radius = this.getRadius();
		}

		int twoRadius = 2 * radius;
		g.fillOval(ix - radius, iy - radius, twoRadius, twoRadius);

		Stroke previousStroke = g.getStroke();
		g.setStroke(this.getStroke());

		twoRadius = 2 * this.getRadius();
		g.drawOval(ix - this.getRadius(), iy - this.getRadius(), twoRadius,
				twoRadius);

		g.setStroke(previousStroke);

		node.defaultPointNodeBody(g, tgPanel);
	}
}
